home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / BCDREAL / BCDREAL.INC
Text File  |  1987-04-10  |  1KB  |  33 lines

  1.  { The below is a function to convert BCD real numbers into "normal"
  2.    Turbo Reals.  It runs under "normal" Turbo or Turbo-87.  Very likely
  3.    the only use for it is to read BCD reals from a FILE and convert them.
  4.                              --  Neil J. Rubenking}
  5.  
  6.   TYPE
  7.     RealBCD = array[0..9] of byte;
  8.  
  9.   FUNCTION BCDtoNorm(R : realBCD) : real;
  10.   Var
  11.     I, IntExponent    : Integer;
  12.     N, Tens, Exponent : Real;
  13.     sign              : integer;
  14.   BEGIN
  15.     IF R[0] = 0 THEN BCDtoNORM := 0
  16.     ELSE
  17.       BEGIN
  18.         IntExponent := (R[0] AND $7F) - $3F;
  19.         IF R[0] AND $80 = $80 THEN Sign := -1 ELSE Sign := 1;
  20.         N := 0; Tens := 0.1;
  21.         FOR I := 9 downto 1 DO
  22.           BEGIN
  23.             N := N + Tens*(R[I] SHR 4);
  24.             Tens := Tens * 0.1;
  25.             N := N + Tens*(R[I] AND $F);
  26.             Tens := Tens * 0.1;
  27.           END;
  28.        Exponent := 1.0;
  29.        FOR I := 1 to IntExponent DO Exponent := Exponent * 10.0;
  30.        BCDtoNORM := Exponent * N * Sign;
  31.      END;
  32.   END;
  33.